package lol.clann.bukkit.pluginboot.util;

import lol.clann.clannboot.annotation.inject.Inject;
import lol.clann.clannboot.annotation.svc.Service;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.scheduler.BukkitTask;

/**
 * @author pyz
 * @date 2018/8/17 下午11:02
 */
@Service(priority = Integer.MAX_VALUE)
public class TaskUtils {

    @Inject
    private BukkitScheduler scheduler;

    public BukkitTask runTaskAsynchronously(Runnable runnable) {
        return runTaskAsynchronously(PluginUtils.getCallerPlugin(), runnable);
    }

    public BukkitTask runTaskLater(long delayTick, Runnable runnable) {
        return scheduler.runTaskLater(PluginUtils.getCallerPlugin(), runnable, delayTick);
    }

    public BukkitTask runTaskLaterAsynchronously(long delayTick, Runnable runnable) {
        return runTaskLaterAsynchronously(PluginUtils.getCallerPlugin(), delayTick, runnable);
    }

    public BukkitTask runTaskTimer(long delayTick, long intervalTick, Runnable runnable) {
        return runTaskTimer(PluginUtils.getCallerPlugin(), delayTick, intervalTick, runnable);
    }

    public BukkitTask runTaskTimerAsynchronously(long delayTick, long intervalTick, Runnable runnable) {
        return runTaskTimerAsynchronously(PluginUtils.getCallerPlugin(), delayTick, intervalTick, runnable);
    }

    public BukkitTask runTaskAsynchronously(Plugin plugin, Runnable runnable) {
        return scheduler.runTaskAsynchronously(plugin, runnable);
    }

    public BukkitTask runTaskLater(Plugin plugin, long delayTick, Runnable runnable) {
        return scheduler.runTaskLater(plugin, runnable, delayTick);
    }

    public BukkitTask runTaskLaterAsynchronously(Plugin plugin, long delayTick, Runnable runnable) {
        return scheduler.runTaskLaterAsynchronously(plugin, runnable, delayTick);
    }

    public BukkitTask runTaskTimer(Plugin plugin, long delayTick, long intervalTick, Runnable runnable) {
        return scheduler.runTaskTimer(plugin, runnable, delayTick, intervalTick);
    }

    public BukkitTask runTaskTimerAsynchronously(Plugin plugin, long delayTick, long intervalTick, Runnable runnable) {
        return scheduler.runTaskTimerAsynchronously(plugin, runnable, delayTick, intervalTick);
    }


}
